#include "square.h"

square::square(const point &upper_left, int w):rect(upper_left,w,w){}

void square::Draw(HWND hwnd,int xt, int yt)
{
	if(xt<100)
		xt=100;
	else if(xt>700)
		xt=700;
	if(yt>600)
		yt=600;
	SetWidth(xt - m_pos.GetX());
	SetHight(yt - m_pos.GetY());

	HDC hdc = GetDC(hwnd);
	
		Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());

	ReleaseDC (hwnd, hdc) ;
}

void square::Draw(HWND hwnd)
{

	HDC hdc = GetDC(hwnd);

		Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());

	ReleaseDC (hwnd, hdc) ;
}

void square::Hide(HWND hwnd)
{
	
	HDC hdc = GetDC(hwnd);

		HPEN hPen = CreatePen (PS_SOLID,1,RGB(255,255,255));
		SelectObject (hdc, hPen);
		Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());
		DeleteObject(hPen);

	ReleaseDC (hwnd, hdc) ;
}

bool square::operator==(const square &right) const
{
	if(!(m_pos == right.m_pos))
		return false;
	if(m_width != right.GetWidth() || m_hight != right.GetHight())
		return false;

	return true;
}

const square& square::operator =(const square &right)
{
	if(this != &right)
	{
		m_pos = right.m_pos;
		SetWidth(right.GetWidth());
		SetHight(right.GetHight());
	}

	return *this;
}

ostream& operator<<(ostream &output,square s)
{
	output << "pos = " << s.m_pos << "," << "size = " <<s.m_width << endl;

	return output;
}